package com.store.practice.service.impl;

import com.github.pagehelper.PageHelper;
import com.store.practice.mapper.BgSkillTagMapper;
import com.store.practice.mapper.BgStorestaffSkilltagRelationMapper;
import com.store.practice.model.BgSkillTag;
import com.store.practice.model.BgStorestaffSkilltagRelation;
import com.store.practice.model.BgStorestaffSkilltagRelationExample;
import com.store.practice.service.BgSkillTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class BgSkillTagServiceImpl implements BgSkillTagService {
    @Autowired
    private BgSkillTagMapper tagMapper;
    @Autowired
    private BgStorestaffSkilltagRelationMapper storestaffSkilltagRelationMapper;

    @Override
    public int insert(BgSkillTag tag) {
        return tagMapper.insert(tag);
    }

    @Override
    public int delete(Integer id) {
        int i = tagMapper.deleteByPrimaryKey(id);
        BgStorestaffSkilltagRelationExample example = new BgStorestaffSkilltagRelationExample();
        example.createCriteria().andSkillIdEqualTo(id);
        storestaffSkilltagRelationMapper.deleteByExample(example);
        return i;
    }

    @Override
    public int update(BgSkillTag tag) {
        return tagMapper.updateByPrimaryKey(tag);
    }

    @Override
    public List<BgSkillTag> list(int pageNum,int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        return tagMapper.selectByExample(null);
    }
}
